<?
	class SiteView extends View{
		
		function SiteView($template_path){
			$this->template_path=$template_path;
			$this->_msgs=array();
			$this->_heads=array();
			Model::SetLang(mod("Language",array(getlang())));
			if(method_exists($this,"init")) $this->init();
			
		}
		
		
		function getLangURL($langcode){	
			return BASE."/{$langcode}".ereg_replace("^".urlbase(),"",$_SERVER["REDIRECT_URL"]).(empty($_SERVER["REDIRECT_QUERY_STRING"])?"":"?").$_SERVER["REDIRECT_QUERY_STRING"];
		}
		
		function strip(){
			//$this->_template_file=dirname(__FILE__)."/{$this->path}/{$this->strip_file}";
			$this->file = $this->strip_file;
		}
		
		function initLang(){
			if(getlang()!=DEF_LANG){
				$file=pathjoin(dirname($this->getTemplateFile()),"main.lang",getlang().".php");
				if(file_exists($file)) {
					$this->parseLang($file);
				}
				$this->_lang=$_lang;
			}
		}
		
		function initScript(){
			$head="<script>";
			$head.="function getTemplateBase(){";
			$head.="return '{$this->template_base}'";
			$head.="}";
			$head.="</script>";
			$head.=$this->head;
			$this->head=$head;
		}
		
		function addHead($html){
			$heads = $this->_heads;
			$heads[]=$html;
			$this->_heads=$heads;
			
		}
		
		
		
		
		function addMsg($msg){
			$msgs = $this->_msgs;
			$msgs[]=$msg;
			$this->_msgs=$msgs;
		}
		
		
		function getTemplateFile(){
			return pathjoin($this->template_path,$this->file);
		}
		
		function getContentFile(){
			return $this->content_file;
		}
		
		
		function render($file=NULL){
			
			$this->template_base = $this->base = pathjoin(BASE,ereg_replace("^".ROOT,"",dirname($this->getTemplateFile())));
			
			$this->content_file = $file;	
			
			if(getlang()!=DEF_LANG){
				$content_lang_file=pathjoin(dirname($file),basename($file,"php")."lang",getlang().".php");
				if(file_exists($content_lang_file)) $this->parseLang($content_lang_file);
				//$this->_lang=$_lang;
			}
			
			if(!file_exists($file)){
				redirect("page_not_found");
			}
			
			$this->parse($file);
				
			if(method_exists($this,"onBeforeRender")) $this->onBeforeRender();
			
			$this->initLang();
			
			$this->initScript();
			
			return parent::render($this->getTemplateFile());

		}
		
	}
?>
